package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.recharge.FindActivityResult;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.player.RechargeModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.webservice.GamePublicFunction;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.List;

/**
 * 限时充值 特惠礼包
 */
public class RechargeActivityRecharge extends BaseRecharge {

    private ActivityConditionInfo activityConditionInfo;

    public RechargeActivityRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        FindActivityResult findResult = GamePublicFunction.findActivityMall(mallInfo.getMallId());
        if(!findResult.isFind()){
            return true;
        }
        activityConditionInfo = findResult.getActivityConditionInfo();
        ActivityModule activityModule = player.getModule(ActivityModule.class);
        BaseActivityData baseActivityData = activityModule.getBaseActivityData(activityInfo.getActivityId());
        if (null == baseActivityData) {
            return true;
        }
        int ret = activityModule.queryActivityMallCanBuy(activityInfo.getActivityId(), activityConditionInfo.getConditionId());
        return ret != 0;
    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        player.notifyListener(eGamePlayerEventType.RechargeItem.getValue(), mallInfo.getMallId());
        RechargeModule rechargeModule = player.getModule(RechargeModule.class);
        //每日特惠-财神赠礼-开服豪礼
        rechargeModule.notifyNewRechargeActivity(mallInfo.getMallId());
        String rewardStr = "";
        if(null != activityConditionInfo){
            rewardStr = activityConditionInfo.getRewardStr();
            if (activityConditionInfo.getType() == eGamePlayerEventType.ExpressionActivityChoose.getValue()) {
                ActivityModule activityModule = player.getModule(ActivityModule.class);
                BaseActivityData baseActivityData = activityModule.getBaseActivityData(activityConditionInfo.getActivityId());
                if(null != baseActivityData) {
                    UserActivityConditionData userActivityConditionData = baseActivityData.getUserActivityConditionData(activityConditionInfo.getConditionId());
                    if(null != userActivityConditionData) {
                        if (userActivityConditionData.getValue().intValue() == 2) {
                            rewardStr = activityConditionInfo.getMasterRewardStr();
                        }
                    }
                }
            }else if(activityConditionInfo.getType() == eGamePlayerEventType.DailyDiscountOneKeyBuy.getValue()){
                Property property = new Property();
                List<ActivityConditionInfo> activityConditionInfoList = NormalActivityMgr.getActivityConditionInfoList(activityInfo.getActivityId());
                if(null != activityConditionInfoList) {
                    for (ActivityConditionInfo conditionInfo : activityConditionInfoList) {
                        if (conditionInfo.getType() == eGamePlayerEventType.RechargeItem.getValue()) {
                            property.addProperty(conditionInfo.getReward());
                        }
                    }
                }
                rewardStr = PropertyHelper.parsePropertyToString(property);
            }
        }
        return rewardStr;
    }

}
